<?php
namespace app\api\controller\goods;
use think\App;
use app\api\common;
use app\api\ControllerBase;
use app\api\server\goods\RefundOrder as RefundOrderServer;
use think\exception\ValidateException;
/**
 * @title 实体商品退货订单
 */
class RefundOrder extends ControllerBase{
	
    public function __construct(App $app){
        $this->REQUEST=$app->request;
        $this->checkParam($this->REQUEST);
        self::$s_server=new RefundOrderServer($app);
    }
    /**
     * @title 查询后台设置的退货原因
     * @param string page 1 彈幕 
     * @param string limit 20
     */
    public function selectRefundRemark()
    {
    	return $this->commonFunction(__function__);
    }
    /**
     * @title 查询退货订单列表
     * @param string page 1 页数
     * @param string limit 20 每页数量
     * @return string courier_sn - 用户填写的运单号
     * @return string id - 用于后续取消和填写运单号等
     * @return string ordersn - 订单号
     * @return string refund_ordersn - 退款订单号
     * @return string status - [-1取消,0申请退货中1商家已审核2驳回3填写运单号4已完成]
     * @return string time - 自动取消时间 
     * @return string total_money - 退货总金额(从下面的details汇总计算而来的)
     * @return string total_num - 退货总数量(从下面的details汇总计算而来的)
     * @return array details - 具体退货的信息
     * @return string details.img - 当次退货的商品图片
     * @return string details.refund_money - 退货的货品单价
     * @return string details.refund_num - 退货的数量
     * @return string details.title - 退货的商品名称
     * @return string details.goods_sku - 退货的商品规格
     * @return string details.discount_money - 退货商品小计汇总	
     */
    public function selectRefundOrder(){
    	return $this->commonFunction(__function__);
    }
    /**
     * @title 申请退货
     * @param int id 50002133252049778 订单Id
     * @param string images https,https 图片,多个以逗号隔开
     * @param string remark - 退货原因
     * @param string data[0][order_details_id] 50002133256244234 订单商品详情id
     * @param string data[0][refund_num] 1 需退货商品数量
     */
    public function refund(){
    	$_param=$this->REQUEST->param();
		$checkFlag = $this->checkVailDate(\app\api\validate\Goods::class,__function__);
        if ($checkFlag == false) {
            return common::return_json($checkFlag, $this->ERROR, $this->CODE);
        }
        try {
            foreach ($_param['data'] as $k => $v) {
                $r = validate(\app\api\validate\Goods::class)->scene('refund_data')->check($v);
            }
        } catch (ValidateException $e) {
            $this->getMessageCode('adminMessage.field.error', 1);
            $this->ERROR = $this->ERROR . ',' . $e->getError();
            return common::return_json([], $this->ERROR, $this->CODE);
        }
    	return $this->commonFunction(__function__);
    }
    
    /**
     * @title 取消退货
     * @param int id 50002133252049778 订单Id
     */
    public function cancleRefundOrder(){
    	return $this->commonFunction(__function__);
    }
    
    
    /**
     * @title 填写运单号
     * @param int id 50002133252049778 订单Id
     * @param string company_id 1 快递公司id
     * @param string courier_sn 1111111 快递单号
     */
    public function writeRefundCourierData(){
    	$checkFlag = $this->checkVailDate(\app\api\validate\Goods::class,__function__);
        if ($checkFlag == false) {
            return common::return_json($checkFlag, $this->ERROR, $this->CODE);
        }
    	return $this->commonFunction(__function__);
    }
}
?>